<?php
namespace controller;

/**
 * Generic front controller
 * @author milena
 *
 */
class BaseController
{
 
    /**
     * Show error 404
     * @return string
     */
    public function execute404()
    {
        $this->sendNotFoundHeaders();
        return "Unvailable";
    }

    /**
     * Show error 405
     * @return string
     */
    public function execute405()
    {
        $this->sendNotFoundHeaders();
        return "Method not allowed";
    }

    /**
     * Send headers for JSON output
     */
    protected function sendJsonHeaders()
    {
        // Prevent caching.
        header('Cache-Control: no-cache, must-revalidate');
        header('Expires: Mon, 01 Jan 1996 00:00:00 GMT');
        
        // The JSON standard MIME header.
        header('Content-type: application/json');
    }

    /**
     * Send headers 200
     */
    protected function sendSuccessHeaders()
    {
        header("HTTP/1.1 200 OK");
    }
    
    /**
     * Send headers for error 500
     */
    protected function sendErrorHeaders()
    {
        header("HTTP/1.1 500 Server Error");
    }

    /** 
     * Send headers for error 404
     */
    protected function sendNotFoundHeaders()
    {
        header('HTTP/1.1 404 Not Found');
    }
}
